package com.todod.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.todod.dto.PublicFileEvaluateDto;
import com.todod.entity.QueryPublicFile;
import com.todod.entity.ResultData;
import com.todod.mapper.PublicFileEvaluateMapper;
import com.todod.model.PublicFileEvaluate;
import com.todod.service.PublicFileEvaluateService;

/**
 * @author lql
 * @date 2020年12月25日
 */
@RestController
@RequestMapping("/publicFileEvaluate")
public class PublicFileEvaluateController extends BaseManageController {

	@Autowired
	public PublicFileEvaluateService publicFileEvaluateService;
	@Autowired
	public PublicFileEvaluateMapper publicFileEvaluateMapper;

	/**
	 * 
	 * @param companyId
	 * @param _userId
	 * @param request
	 * @param queryPublicFileEvaluate
	 * @return
	 */
	@RequestMapping("/getListPage")
	public ResultData getListPage(@RequestAttribute Long _userId, HttpServletRequest request,
			@RequestBody QueryPublicFile queryPublicFileEvaluate) {

		IPage<PublicFileEvaluateDto> page = publicFileEvaluateService.getListPage(_userId, queryPublicFileEvaluate);
		return ResultData.success("ok", page);
	}

	/**
	 * 
	 * @param _userId
	 * @param reqPublicFileEvaluate
	 * @return
	 */
	@PostMapping("/save")
	public ResultData saveData(@RequestAttribute Long _userId, @RequestBody PublicFileEvaluate publicFileEvaluate) {

		publicFileEvaluateService.saveData(_userId, publicFileEvaluate);

		return ResultData.success();
	}

	/**
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public ResultData delete(String ids) {

		String[] id = ids.split(",");
		for (int i = 0; i < id.length; i++) {
			publicFileEvaluateMapper.deleteById(id[i]);
		}
		return ResultData.success();
	}

	/**
	 * 
	 * @param code
	 * @return
	 */
	@GetMapping("/getInfo")
	public ResultData getInfo(Long code) {
		if (code == null) {
			return ResultData.error(ResultData.PARAM_ERROR_CODE, "参数错误");
		}
		return ResultData.success("ok", publicFileEvaluateService.getInfo(code));
	}

	/**
	 * 
	 * @param code
	 * @return
	 */
	@GetMapping("/getEvaluateList")
	public ResultData getEvaluateList(Long fileId) {
		if (fileId == null) {
			return ResultData.error(ResultData.PARAM_ERROR_CODE, "参数错误");
		}
		return ResultData.success("ok", publicFileEvaluateService.getEvaluateList(fileId));
	}

}
